extends Area2D

signal item_despawned(score_amount)

@onready var timer = $Timer

var collected = false
var start_time = 25.0

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	timer.wait_time = start_time
	timer.start()
	
	





func _on_body_entered(body: Node2D) -> void:
	if body.is_in_group("player"):
		if collected == false:
			collected = true
			print ("item collected - time bonus: " + str(timer.time_left))
			emit_signal("item_despawned", timer.time_left)
			await get_tree().create_timer(0.1).timeout
			call_deferred("queue_free")


	
func _on_timer_timeout() -> void:
	if collected == false:
		emit_signal("item_despawned", -start_time)
		await get_tree().create_timer(0.1).timeout
		call_deferred("queue_free")
